import request from '../utils/request'

// 请求轮播图请求
export function requestSwiper () {
    return new Promise(resolve => {
        request.get('/banner/list').then(res => {
            resolve(res.data)
        })
    })
}

// 获取销量排行top5数据
export function requestHotSell () {
    return new Promise(resolve => {
        request.get('/pro/sellbest').then(res => {
            resolve(res.data)
        })
    })
}

// 请求秒杀的数据列表
export function requestSecondKill (params = {}) {
    return new Promise(resolve => {
        request.get('/pro/seckill', {
            params,
        }).then(res => {
            resolve(res.data)
        })
    })
}

// 请求上新商品数据
export function requestNewList () {
    return new Promise(resolve => {
        request.get('/pro/new').then(res => {
            resolve(res.data)
        })
    })
}

// 请求推荐商品数据
export function requestRecommandList () {
    return new Promise(resolve => {
        request.get('/pro/recomend', {
            headers: {
                loading: true
            }
        }).then(res => {
            resolve(res.data)
        })
    })
}

//请求商品分页数据
export function requestPageTo (page = 1) {
    return new Promise(resolve => {
        request.get('/pro/list', {
            params: {
                count: page,
                limitNum: 10
            },
            headers: {
                loading: true
            }
        }).then(res => {
            resolve(res.data)
        })
    })
}

//获取商品详情
export function requestShoppingDetail (proid) {
    return new Promise(resolve => {
        request.get('/pro/detail/' + proid, {
            headers: {
                loading: false
            }
        }).then(res => {
            resolve(res.data)
        })
    })
}

//获取某分类下商品数据
export function requestShoplistByClassify (category, nin = []) {
    return new Promise(resolve => {
        request.get('/pro/getListByCategory', {
            params: {
                category,
                nin
            },
            headers: {
                loading: true
            }
        }).then(res => {
            resolve(res.data)
        })
    })
}

export function getShoplistOrderBySales (sales, category) {
    return new Promise(resolve => {
        request.get('/pro/getListOrderBySell', {
            params: {
                sales,
                category
            }
        }).then(res => {
            resolve(res.data)
        })
    })
}

export function getShoplistOrderByPrice (originprice, category) {
    return new Promise(resolve => {
        request.get('/pro/getListOrderByPrice', {
            params: {
                originprice,
                category
            }
        }).then(res => {
            resolve(res.data)
        })
    })
}

export function getShoplistOrderByDiscount (discount, category) {
    return new Promise(resolve => {
        request.get('/pro/getListOrderByDiscount', {
            params: {
                discount,
                category
            }
        }).then(res => {
            resolve(res.data)
        })
    })
}

export function getMultiFilterShoplist (params) {
    return new Promise(resolve => {
        request.get('/pro/filter', {
            params
        }).then(res => {
            resolve(res.data)
        })
    })
}

export function getSearchShoplist (value) {
    return new Promise(resolve => {
        request.get('/pro/search', {
            params: {
                value
            }
        }).then(res => {
            resolve(res.data)
        })
    })
}

//商品评价
export function requestComments (data) {
    return new Promise(resolve => {
        request.post('/comment/add', data).then(res => {
            resolve(res.data)
        })
    })
}

// 获取商品评价
export function requestGetComments (proid) {
    return new Promise(resolve => {
        request.get('/comment/list', {
            params: {
                proid
            }
        }).then(res => {
            resolve(res.data)
        })
    })
}

// 获取我的商品评价
export function requestMyComments () {
    return new Promise(resolve => {
        request.get('/comment/my', {
            params: {
                userid: localStorage.getItem('userid')||''
            }
        }).then(res => {
            resolve(res.data)
        })
    })
}
